package ex2.employee;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CEmployeeHandler implements IEmployeeHandler {

	private Collection<IEmployee> _employees;
	
	public CEmployeeHandler(){
		this._employees = new ArrayList<IEmployee>();
	}
	
	
	public void addEmployee(IEmployee employee){
		this._employees.add(employee);
	}
	
	public Collection<IEmployee> getEmployee(){
		return this._employees;
	}
	
	
	
	@Override
	public double getTotalExpenses(String username) {
		IEmployee tIteratorEmployee=null;
		double Expenses=0;
		
		for(Iterator<IEmployee> iterator = _employees.iterator(); iterator.hasNext();){
			
			tIteratorEmployee=iterator.next();
			
			if(tIteratorEmployee.getUsername().equals(username)){		
				Expenses=tIteratorEmployee.calaulateTotalExpenses();
				break;
			}
		}
			
		return Expenses;
	}

	@Override
	public boolean isAvailableUsername(String username) {
		
		IEmployee tIteratorEmployee=null;
		for(Iterator<IEmployee> iterator = _employees.iterator(); iterator.hasNext();){
			
			tIteratorEmployee=iterator.next();
			
			if(tIteratorEmployee.getUsername().equals(username))
				return false;
		}
		return true;
	}


	@Override
	public void clearRedundantEmployees() {
		IEmployee tIteratorEmployee=null;
		
		for(Iterator<IEmployee> iterator = _employees.iterator(); iterator.hasNext();){
			
			tIteratorEmployee=iterator.next();				
			if (tIteratorEmployee.getEmployeeCode().equals("1"))
				tIteratorEmployee.deleteRedundantData();

		}
		
	}


	@Override
	public void clearRedundantEquipment() {
		IEmployee tIteratorEmployee=null;
		
		for(Iterator<IEmployee> iterator = _employees.iterator(); iterator.hasNext();){
			
			tIteratorEmployee=iterator.next();				
			if (tIteratorEmployee.getEmployeeCode().equals("2"))
				tIteratorEmployee.deleteRedundantData();
		}
		
	}


	@Override
	public Collection<IEmployee> getEmployees() {
		return this._employees;
	}
	

}
